package cn.linlane.service.sys;

import cn.linlane.dao.sys.SysDepartDao;
import cn.linlane.dao.sys.SysUserDao;
import cn.linlane.entity.sys.SysUser;
import cn.linlane.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserService extends BaseService<SysUserDao, SysUser> {

    @Autowired
    private SysDepartDao sysDepartDao;

    public SysUser findByUsername(String username) {
        return baseDao.findByAccount(username);
    }

    public boolean existByAccount(String account){
        return baseDao.existsByAccount(account);
    }

    /**
     * 根据用户名查询
     *
     * @param account
     * @return
     */
    public List<SysUser> findByAccount(String account) {
        return baseDao.findAllByAccount(account);
    }

    /**
     * 根据部门编号和用户账户或姓名查询
     */
    public Page<SysUser> getDeparts(String storeCode, String searchKey, Integer pageNum, Integer pageSize){
        return baseDao.fetchAllBystoreCode(storeCode, searchKey, PageRequest.of(pageNum, pageSize));
    }

}
